<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7_2_1-2计算变量赋值</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

  <div id="Application"></div>
  <script>
    const App = Vue.createApp({
      setup() {
        let a = Vue.ref(1);
        let b = Vue.ref(2);
        let sum = Vue.computed({
          //拿值
          get() {
            return a.value + b.value;
          },
          //改变值
          set(value) {
            a.value = value;
            b.value = value;
          },
        });
        function click() {
          a.value += 1;
          b.value += 2;
          console.log(a.value);
          console.log(b.value);
          if (sum.value > 10) {
            sum.value = 0;
          }
        }
        return {
          sum,
          click,
          a,
          b,
        };
      },
      template: `
            <h1>测试数据：{{sum}}</h1>a：{{a}}，b：{{b}}
            <button @click="click">点击</button>
            `,
    });
    App.mount("#Application");
  </script>
</body>

</html>